<%@page import="com.project.XXXX.model.tbl_workplace"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=utf-8"%>
<%@page import="com.project.XXXX.model.tbl_ptjobWithBLOBs "%>
<%@page import="com.project.XXXX.model.tbl_sysuser"%>
<%@page import="com.project.XXXX.model.tbl_employerinfo "%>
<%@page import="com.google.gson.Gson"%>
<%@page import="com.project.XXXX.stringmodel.PtJobAddress"%>

<!doctype html>
<html class="no-js">
<head>

<link rel="stylesheet" href="assets/css/amazeui.datetimepicker.css" />

<script src="assets/js/pagejs/Job-Posted.js"></script>
<%@ include file="../commoms/link.txt"%>
<meta name="description" content="Job_Posted">
<style type="text/css">
label {
	font-family: sans-serif;
}

#timebegin{
cursor:pointer;
background-color: #FFFFFF;
}
#timeend{
cursor:pointer;
background-color: #FFFFFF;
}
#beginDate{
cursor:pointer;
background-color: #FFFFFF;
}
#endDate{
cursor:pointer;
	background-color: #FFFFFF;
}
div[name] {
	padding: 20px, 10px, 10px, 20px;
}

h2 {
	margin: 10px;
	padding: 10px;
	font-family: sans-serif;
	background-color: #F0FFFF;
}
</style>
</head>
<body>
	<%@ include file="../commoms/ERHeader.txt"%>
	<%!tbl_ptjobWithBLOBs tbl_ptjobWithBLOBs = null;
	List<PtJobAddress> lworkspace = null;

	Gson g = new Gson();%>
	<%
		boolean isNew = true;
		tbl_sysuser tbl_sysuser = null;
		tbl_employerinfo tbl_employerinfo = null;
		tbl_sysuser = (tbl_sysuser) session.getAttribute("User");
		tbl_employerinfo = (tbl_employerinfo) session.getAttribute("ERinfo");
		if (tbl_sysuser != null) {
			lworkspace = (List<PtJobAddress>) session.getAttribute("ptJobworkspace");
			tbl_ptjobWithBLOBs = (tbl_ptjobWithBLOBs) session.getAttribute("ptJob");
			if (tbl_ptjobWithBLOBs != null) {
				isNew = false;
				session.removeAttribute("ptJobworkspace");
				session.removeAttribute("ptJob");
			}
		}
	%>

	<div id="admin-content">

		<form action="JobPost.do" method="post" id="JobPostformtooltip"
			class="am-form am-form-horizontal" data-am-validator id="jobinfo">
			<fieldset>
				<legend>职位信息</legend>
			
					<div id="baseInfo">
						<h2 class="am-u-lg-11 am-u-end">基本信息</h2>
						<div class="am-form-group am-u-lg-12">
							<label for="title" class="am-u-lg-2 am-form-label">职位名称</label>
							<div class="am-u-lg-10 ">
								<input type="text" name="title" class="am-form-field "
									id="title" placeholder="职位名称不能超过15个字"  style="width: 45%" 
									maxlength="15" data-foolish-msg="请输入职位名称" required
									<%if (!isNew) {%> value=<%=tbl_ptjobWithBLOBs.getTitle()%>
									<%}%>>
							</div>
						</div>
						<div class="am-form-group am-u-lg-12">
							<label for="pttypeid" class="am-u-lg-2 am-form-label">工作类型</label>
							<div class="am-u-lg-10 am-u-sm-12">
								<select id="pttypeid" class="am-form-field" name="pttypeid"
									style="width: 18%">
									<%
								int t = 1;
								String[] types = {"传单派发", "促销导购", "话务客服", "礼仪模特", "老师家教", "服务员", "问卷调查", "审核录入", "地推拉访", "其它"};
								if (!isNew) {
									t = tbl_ptjobWithBLOBs.getPttypeid();
								}
								for (int i = 0; i < 10; i++) {
									if (t != (i + 1)) {
							%>
									<option value=<%=i + 1%>><%=types[i]%>
									</option>
									<%
								} else {
							%>
									<option value=<%=i + 1%> selected="selected"><%=types[i]%>
									</option>
									<%
								}

								}
							%>

								</select>
							</div>
						</div>
						<div class="am-form-group am-u-lg-12">
							<label for="place" class="am-u-lg-2 am-form-label">工作城市</label>
							<div id="place">
								<div class="am-u-lg-10 am-u-sm-12">
									<select id="s_province" name="s_province" class="am-inline"
										style="width: 15%" onchange="changecity(this)"
										onclick="changeplace(this)"></select>&nbsp;&nbsp; <span
										id="city"></span> <span id="contry"></span>
								</div>
							</div>
						</div>


				
				</div>
				<%
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				
				%>
				<div id="times">
					<h2 class="am-u-lg-11">工作时间</h2>

					<div class="am-form-group am-u-lg-12">
						<label for="beginDate" class="am-u-lg-2 am-form-label am-inline">工作日期</label>
                         <div class="am-u-lg-10 am-u-sm-12">
						<input type="text" class="am-form-field am-inline" id="beginDate"
							name="beginDate" class="am-form-field" style="width: 20%"
							placeholder="开始日期" required <%if (!isNew) {%>
							value=<%=sdf.format(tbl_ptjobWithBLOBs.getBegindate() )%> <%}%>
							readonly> <label for="endDate"
							class="am-form-label am-inline">到</label> <input type="text"
							class="am-form-field am-inline" style="width: 20%" id="endDate"
							name="endDate" required placeholder="结束日期" <%if (!isNew) {%>
							value=<%=sdf.format(tbl_ptjobWithBLOBs.getEnddate())%> <%}%>
							readonly>
         </div>
					</div>

					<div class="am-form-group am-u-lg-12">
						<label for="timebegin" class="am-u-lg-2 am-form-label">时间段</label>
                           <div class="am-u-lg-10 am-u-sm-12">
						<input type="text" id="timebegin" name="timebegin"
							class="am-form-field am-inline" style="width: 20%" required
							placeholder="开始时间" readonly> <label for="timeend"
							class="am-form-label am-inline">到</label> <input type="text"
							id="timeend" name="timeend" class="am-form-field am-inline"
							style="width: 20%" required placeholder="结束时间" readonly>
					</div>
</div>
				</div>


				<div id="employee">
					<h2 class="am-u-lg-11">人员要求</h2>
					<div class="am-form-group am-u-lg-12">
						<label for="personnum" class="am-u-lg-2 am-form-label">招聘人数</label>
						<div class="am-u-lg-10 am-u-sm-12">
							<input type="text" class="am-form-field" style="width: 15%"
								id="personnum" name="personnum" pattern="[0-9]"
								data-foolish-msg="必填" required <%if (!isNew) {%>
								value=<%=tbl_ptjobWithBLOBs.getPersonnum()%> <%}%>>
						</div>
					</div>
					<div class="am-form-group am-u-lg-12">
						<label for="genderneedid" class="am-u-lg-2 am-form-label">性别要求</label>
						<div class="am-u-lg-10 am-u-sm-12">
							<select id="genderneedid" name="genderneedid"
								class="am-form-field" style="width: 15%">
								<%
								t = 15;
								String[] Sexes = {"男", "女", "不限"};
								if (!isNew) {
									t = tbl_ptjobWithBLOBs.getGenderneedid();
								}
								for (int i = 12; i < 15; i++) {
									if (t != (i + 1)) {
							%>
								<option value=<%=i + 1%>><%=Sexes[i - 12]%>
								</option>
								<%
								} else {
							%>
								<option value=<%=i + 1%> selected="selected"><%=Sexes[i - 12]%>
								</option>
								<%
								}

								}
							%>

							</select>
						</div>
					</div>



					<div class="am-form-group am-u-lg-12">
						<label class="am-u-lg-2 am-form-label" for="sex">是否面试</label>
						<div class="am-u-lg-10 am-u-sm-12">
							<div id="interview">
								<%
								t = 37;
								String[] interview = {"是", "否"};
								if (!isNew) {
									t = tbl_ptjobWithBLOBs.getInterview();
								}
								for (int i = 35; i < 37; i++) {
									if (t != (i + 1)) {
							%>
								<label class="am-radio-inline"> <input type="radio"
									name="interview" value=<%=i + 1%>><%=interview[i - 35]%></label>

								<%
								} else {
							%>
								<label class="am-radio-inline"> <input type="radio"
									name="interview" value=<%=i + 1%> checked="checked"><%=interview[i - 35]%>
								</label>
								<%
								}

								}
							%>

							</div>
						</div>
					</div>
					<div class="am-form-group am-u-lg-12">
						<label class="am-u-lg-2 am-form-label" for="sex">是否培训</label>
						<div class="am-u-lg-10 am-u-sm-12">
							<div id="train">


								<%
								t = 39;
								String[] train = {"是", "否"};
								if (!isNew) {
									t = tbl_ptjobWithBLOBs.getTrain();
								}
	
								for (int i = 37; i < 39; i++) {
									if (t != (i + 1)) {
							%>
								<label class="am-radio-inline"> <input type="radio"
									name="train" value=<%=i + 1%>><%=train[i - 37]%></label>

								<%
								} else {
							%>
								<label class="am-radio-inline"> <input type="radio"
									name="train" value=<%=i + 1%> checked="checked"><%=train[i - 37]%>
								</label>
								<%
								}

								}
							%>

							</div>


						</div>
					</div>



				</div>
				<div id="reward">
					<h2 class="am-u-lg-11">薪资待遇</h2>
					<div class="am-form-group am-u-lg-12">
						<label for="salaryunit" class="am-u-lg-2 am-form-label am-inline">底薪</label>
						<div class="am-u-lg-10 am-u-sm-12">
							<select id="salaryunit" name="salaryunit"
								class="am-form-field am-inline" style="width: 15%">
								<%
								t = 16;
								String[] salaryunit = {"天", "周", "小时", "次", "个", "件"};
								if (!isNew) {
									t = tbl_ptjobWithBLOBs.getSalaryunit();
								}
								for (int i = 15; i < 21; i++) {
									if (t != (i + 1)) {
							%>
								<option value=<%=i + 1%>><%=salaryunit[i - 15]%>
								</option>
								<%
								} else {
							%>
								<option value=<%=i + 1%> selected="selected"><%=salaryunit[i - 15]%>
								</option>
								<%
								}

								}
							%>

							</select> <input type="text" name="salary" class="am-form-field am-inline"
								style="width: 10%" pattern="[0-9]" data-foolish-msg="请输入底薪"
								required <%if (!isNew) {%>
								value=<%=tbl_ptjobWithBLOBs.getSalary()%> <%}%>>元
						</div>
					</div>
					<div class="am-form-group am-u-lg-12">
						<label for="billcycleid" class="am-u-lg-2 am-form-label">结算周期</label>
						<div class="am-u-lg-10 am-u-sm-12">
							<select id="billcycleid" name="billcycleid"
								class="am-form-field am-inline" style="width: 15%">
								<%
								t = 22;
								String[] billcycleid = {"日结", "周结", "半月结", "月结", "完工结"};
								if (!isNew) {
									t = tbl_ptjobWithBLOBs.getBillcycleid();
								}

								for (int i = 21; i < 26; i++) {
									if (t != (i + 1)) {
							%>
								<option value=<%=i + 1%>><%=billcycleid[i - 21]%>
								</option>
								<%
								} else {
							%>
								<option value=<%=i + 1%> selected="selected"><%=billcycleid[i - 21]%>
								</option>
								<%
								}

								}
							%>

							</select>

						</div>
					</div>
				</div>


				<div id="JobRequirement">
					<h2 class="am-u-lg-11">工作要求</h2>
					<div class="am-form-group am-u-lg-12">
						<label for="contect" class="am-u-lg-2 am-form-label">工作内容</label>
						<div class="am-u-lg-10 am-u-sm-12">
							<%
							if (!isNew)
								out.print(
										"<textarea rows=\"6\" id=\"contect\" name=\"contect\" class=\"am-form-field am-inline\" style=\"width: 50%\" placeholder=\"请输入工作内容\" maxlength=\"55\" data-foolish-msg=\"请输入工作内容\"required>"
												+ tbl_ptjobWithBLOBs.getRequirement() + "</textarea>");
							else
								out.print(
										"<textarea rows=\"6\" id=\"contect\" name=\"contect\" class=\"am-form-field am-inline\" style=\"width: 50%\" placeholder=\"请输入工作内容\"  maxlength=\"55\" data-foolish-msg=\"请输入工作内容\"required></textarea>");
							out.flush();
						%>

						</div>
					</div>

					<div class="am-form-group am-u-lg-12">
						<label for="JobRequirement" class="am-u-lg-2 am-form-label">岗位要求</label>
						<div class="am-u-lg-10 am-u-sm-12">
							<%
							if (!isNew)
								out.print(
										"<textarea rows=\"6\" id=\"requirement\" name=\"requirement\" class=\"am-form-field am-inline\" style=\"width: 50%\" placeholder=\"请输入职位要求，如果没有请勿填写，限制30字\" >"
												+ tbl_ptjobWithBLOBs.getRequirement() + "</textarea>");
							else
								out.print(
										"<textarea rows=\"6\" id=\"requirement\" name=\"requirement\" class=\"am-form-field am-inline\" style=\"width: 50%\" placeholder=\"请输入职位要求，如果没有请勿填写，限制30字\" ></textarea>");
							out.flush();
						%>

						</div>
					</div>

					<ul id="placewithword"
						class="am-u-lg-11  am-list am-list-static am-list-border am-list-striped">

					</ul>
					<div class="am-form-group am-u-lg-12">
						<label for="JobPlaceAdd" class="am-u-lg-2 am-form-label">工作地点</label>
						<div class="am-u-lg-10 am-u-sm-12">
							<button id="JobPlaceAdd" onclick="drawmap(this)"
								class="am-form-field am-btn am-icon-plus am-btn-danger am-btn-xs"
								type="button" style="width: 15%"
								data-am-modal="{target: '#my-popup'}"></button>

							<div class="am-popup" id="my-popup">
								<div class="am-popup-inner">
									<div class="am-popup-hd">
										<h4 class="am-popup-title">添加工作地点</h4>

										<span data-am-modal-close class="am-close">&times;</span>
									</div>
									<div class="am-popup-bd">

										<div class="am-g">
											<div class="am-form-group">
												<div class="am-u-lg-9 am-u-lg-centered">
													<input type="text" id="detailaddress" name="detailaddress"
														placeholder="详细地址">
												</div>
											</div>

											<div id="container"
												style="height: 340px; border: 1px solid gray"
												class="am-u-lg-9 am-u-lg-centered"></div>


											<div id="save" style="margin-top: 20px"
												class="am-u-lg-4 am-u-lg-centered">
												<button type="button" id="saveAddress"
													class="am-form-field am-btn  am-btn-success "
													onclick="saveaddress()">保存</button>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>

				<div class="am-form-group  am-u-lg-12">
					<h2 class="am-u-lg-11">联系方式</h2>

					<div class="am-form-group am-u-lg-12">
						<label for="PhoneNum" class="am-u-lg-2 am-form-label">联系电话</label>
						<div class="am-u-lg-10 am-u-sm-12">
							<input type="text" name="PhoneNum" class="" id="PhoneNum"
								placeholder="请输入手机号或者工作电话" class="am-form-field am-inline"
								style="width: 30%" pattern="1[0-9]{10}" 
								data-foolish-msg="请输入正确的手机号码" <%if (!isNew) {%>
								value=<%=tbl_ptjobWithBLOBs.getMobile()%> <%} else if(tbl_employerinfo!=null){%>
								value=<%=tbl_employerinfo.getTel() %>
								<%}%>>
						</div>
					</div>
				</div>
				<div class="am-form-group" align="center">
					<%
						if (!isNew) {
							if(tbl_ptjobWithBLOBs.getId()!=null)
							{
					%>
					<input type="hidden" name=id value=<%=tbl_ptjobWithBLOBs.getId()%>>
					<%
							}
						}
					%>
					<button id="submit" type="submit"
						class="am-btn am-btn-danger am-btn-xl">立即提交</button>
				</div>

			</fieldset>
		</form>
	</div>

	</div>
</body>
	<%@ include file="../commoms/alert.txt"%>

<script>
var list=new Array();
var i=0;
var map = new BMap.Map("container"); // 创建地图实例
var point = new BMap.Point(116.331398,39.897445);
map.centerAndZoom(point,12);
var address=localCity ;
var province=localCity;
var city=localCity;
var country=localCity;
var countrycode=curruntCity.substring(0,4)+"01";
var citycode=curruntCity;
var provincecode=curruntCity.substring(0,2)+"0000";
var detailAddress='';
var geoaddress='';
var lat='',lng='';
var marker=null;
var myGeo = new BMap.Geocoder();
var isopen=false;
var infoWindow =null;
var timebegin;
var timeend;
var places=0;
var level=14;
 $placewithword=$('#placewithword');
 var $modal = $('#my-popup');
 var $form = $('#JobPostformtooltip');
	function G(id) {
		return document.getElementById(id);
	}

   var nowTemp = new Date();
	    var nowDay = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0).valueOf();
	    var nowMoth = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), 1, 0, 0, 0, 0).valueOf();
	    var nowYear = new Date(nowTemp.getFullYear(), 0, 1, 0, 0, 0, 0).valueOf();
	    var $myStart2 = $('#beginDate');
	    var checkin = $myStart2.datepicker({
	      onRender: function(date, viewMode) {
	        var viewDate = nowDay;
	        switch (viewMode) {
	          case 1:
	            viewDate = nowMoth;
	            break;
	          case 2:
	            viewDate = nowYear;
	            break;
	        }

	        return date.valueOf() < viewDate ? 'am-disabled' : '';
	      }
	    }).on('changeDate.datepicker.amui', function(ev) {
	        if (ev.date.valueOf() > checkout.date.valueOf()) {
	          var newDate = new Date(ev.date)
	          newDate.setDate(newDate.getDate());
	          checkout.setValue(newDate);
	        }

	   
	        checkin.close();
	        $('#endDate')[0].focus();
	    }).data('amui.datepicker');

	    var checkout = $('#endDate').datepicker({
	      onRender: function(date, viewMode) {
	        var inTime = checkin.date;
	        var inDay = inTime.valueOf();
	        var inMoth = new Date(inTime.getFullYear(), inTime.getMonth(), 1, 0, 0, 0, 0).valueOf();
	        var inYear = new Date(inTime.getFullYear(), 0, 1, 0, 0, 0, 0).valueOf();
	        var viewDate = inDay;
	        switch (viewMode) {
	          case 1:
	            viewDate = inMoth;
	            break;
	          case 2:
	            viewDate = inYear;
	            break;
	        }
	        return date.valueOf() < viewDate ? 'am-disabled' : '';
	      }
	    }).on('changeDate.datepicker.amui', function(ev) {
	      checkout.close();
	    }).data('amui.datepicker');
	  
	  $('#timeend').datetimepicker({ 
			  format: 'hh:ii',
			  autoclose : true,
			  startDate:new Date().Format("yyyy-MM-dd"),
			  endDate:new Date(new Date().valueOf()+24*60*60*1000).Format("yyyy-MM-dd"),
			  startView : 1,
			  todayHighlight : true,
			  maxView : 1 }).on('changeDate', function(ev) {
				  
					timeend=ev;
					if(timebegin==null)
						{
						timeend=ev;
						$('#timebegin').focus();
						}
					else
						{
					
						if(timebegin.date.valueOf()>ev.date.valueOf())
							{
						
							$('#timeend').val($('#timebegin').val());
							timeend=timebegin;
							$('#timebegin').focus();
							}
						
						}
				
					
			    });
				
	  
	var timebeginpicker= $('#timebegin').datetimepicker({ 
			  format: 'hh:ii',
			  autoclose : true,
			  startDate:new Date().Format("yyyy-MM-dd"),
			  endDate:new Date(new Date().valueOf()+24*60*60*1000).Format("yyyy-MM-dd"),
			  startView : 1,
			  todayHighlight : true,
			  maxView : 1 }).on('changeDate', function(ev) {
				  timebegin=ev;
				  if(timeend==null)
					{
					  timebegin=ev;
					  
					$('#timeend').focus();
					}
				else
					{
					if(timeend.date.valueOf()<ev.date.valueOf()){
						timebegin=timeend;
						$('#timebegin').val($('#timeend').val());
						$('#timeend').focus();
					}
						
			     }
				    });
	
					setFormValidate($form);
	
	<%if (!isNew) {
		String country = tbl_ptjobWithBLOBs.getCityid() + "";
		String jplace = g.toJson(lworkspace);%>
		places =<%=lworkspace.size()%>
		i=places;
		list =<%=jplace%>
		darwplacewithword();
	
		getPlaceList(domain+'/getProvince.do','s_province',{},<%=country.substring(0, 2) + "0000"%>);
		appendCity();
		getPlaceList(domain+'/getCities.do','s_city',{'Province':'<%=country.substring(0, 2) + "0000"%>'},<%=country.substring(0, 4) + "00"%>);
		appendContry();
		getPlaceList(domain+'/getCountries.do','s_county',{'City':'<%=country.substring(0, 4) + "00"%>'
	},<%=country%>);
		<%
		String timebegin="'"+tbl_ptjobWithBLOBs.getTimebegin()+"'";
		String timeend="'"+tbl_ptjobWithBLOBs.getTimeend()+"'";
		%>
		$('#timebegin').val(<%=timebegin%>);
		$('#timeend').val(<%=timeend%>);
<%} else {%>
	placeInit();
	<%}%>
	$('#submit').click(
			function() {
				var templist = new Array();
				var y = 0;
				if (places <= 0) {
					myAlert('提示','至少添加一个工作地点!!!');
					return false;
				}

				for (x in list) {
					if (list[x].isdel != true) {
						templist[y] = list[x];
						y++;
					}
				}

				$('#JobPostformtooltip').append(
						'<input type="hidden" name="jobplace" value='
								+ JSON.stringify(templist) + '></input>');

				return true;
			});

	$('#detailaddress').blur(function() {
		var text = $('#detailaddress').val();
		address = province + city + country;
		address += text;
		detailAddress = text;
		setPlace(text);
		level = 18;
	});

	function setPlace(myValue) {
		map.clearOverlays(); //清除地图上所有覆盖物
		function myFun() {
			var pp = local.getResults().getPoi(0).point;
			addmarkerf(pp);
			map.centerAndZoom(pp, 18);
		}
		var local = new BMap.LocalSearch(map, {
			onSearchComplete : myFun
		});

		local.search(myValue);
	}
	function saveaddress() {
	
		if (detailAddress != '') {
	  if(geoaddress=='')
		  {
			
		     $('#saveAddress').blur();
		  $('#detailaddress').blur();
		
		  }
	  else
		  {
			var temp = new ptaddress(lat, lng, geoaddress, countrycode, detailAddress,
					false);
			list[i] = temp;
			i++;
			address = province + city + country;
			detailAddress = '';
			geoaddress = '';
			lat = '';
			lng = '';
			$('#detailaddress').val('');
			$modal.modal('toggle');
			darwplacewithword();
			places = places + 1;
		  }
		} else {
			$('#detailaddress').focus();
			myAlert('提示','填写粗略地址');
		}

	}
	myAjax(domain + "/getAllERCount.do", {}, function(
			data) {
		$('#count1').text(data.nostart);
		$('#count2').text(data.started+data.end);
		$('#count3').text(data.finish);
	});
</script>
</body>
</html>
